<template>
	<view class="container bg-w">
		<view class="header uni-flex uni-row flex-between">
			<uni-nav-bar title="安全资讯详情">
				<template slot='left'>
					<view class="flex width-100">
						<i class='iconfont iconfanhui' @click='goBack()'></i>
					</view>
				</template>
			</uni-nav-bar>
		</view>
		<view class="position-r-top">
			<view class="ConsultationDetails">
				<view class="title"> {{ConsultationData.noticeTitle}} </view>
				<view class="type flex ">
					<text class="color-6 margin-r-15">{{ConsultationData.noticeName}}</text>
					<text class="color-6">{{ConsultationData.updateTime}}</text>
				</view>
				<view class="html-style" v-html="ConsultationData.noticeContent"> </view>
				<view class="margin-t-20">
					<view class="theme-color margin-b-20" v-for="(item,index) in attachmentIdsAll" :key='index' @click="preview(item.id)"><i class='iconfont iconfujian mr-5'></i>{{item.name}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getFileInfoAll,getFileInfo } from '@/common/api/api.js'
	import ipConfig from '@/utils/ipconfig.js'
	export default {
		data() {
			return {
				ConsultationData:{},
				attachmentIdsAll:[],
			}
		},
		onLoad() {
			this.ConsultationData = uni.getStorageSync('ConsultationData')
			if(this.ConsultationData.attachmentIds){
				let attachmentIdsNews = this.ConsultationData.attachmentIds.split(',')
				// this.$set(this.ConsultationData,'original',[])
				attachmentIdsNews.forEach((obj,index) => {
					this.attachmentIdsAll.push({
					name:null,
					id:obj
				})
					getFileInfoAll(obj).then(res => {
						if(res.data){
							this.attachmentIdsAll[index].name = res.data.original
						}
					})
				})
			}
		},
		methods: {
			preview(attachmentIds){
				if(attachmentIds){
					// plus.runtime.openURL(ipConfig.ip + 'admin/sys-file/getFileById?id='+attachmentIds, function(res) {
					//   console.log(res);  
					// });
					uni.showLoading({ title:'文件加载中…'})
					uni.downloadFile({
						url: ipConfig.ip + 'admin/sys-file/getFileById?id='+attachmentIds,
						success: function (res) {
							uni.hideLoading()
							let filePath = res.tempFilePath;
							uni.openDocument({
								filePath: filePath,
								success: function (res) {
								}
							});
						}
					});
				}
			}
		}
	}
</script>

<style>
	.ConsultationDetails{padding: 30rpx 3%;}
	.title{font-size: 34rpx;margin-bottom: 10rpx;}
	.type{padding-bottom: 20rpx;border-bottom: 4rpx solid #eee;margin-bottom: 20rpx;}
	.html-style{word-break: break-all;text-align: justify;}
	.html-style >>> p{width: 100%;font-size: 30rpx;line-height: 60rpx;color: #666;}
	.html-style >>> img{width: 100%;height: 360rpx;margin: 20rpx 0;border: 1px solid #eee;box-sizing: border-box;}
	.mr-5{margin-right: 10rpx;}
</style>
